#include <bits/stdc++.h>
using namespace std;

const int N=105;
int n, ans[N][N];
char s[N][N];
int q[N * N][2];

int main(){
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }

  int hd = 1, tl = 0;
  memset(ans, 0x3f, sizeof(ans));

  for (int i = 1; i <= n; i++) {
    q[++tl][0] = i;
    q[tl][1] = i;
    ans[i][i] = 0;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (i != j && s[i][j] != '-') {
        ans[i][j] = 1;
        q[++tl][0] = i;
        q[tl][1] = j;
      }
  }

  while (hd <= tl) {
    int u = q[hd][0], v = q[hd][1];
    hd++;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (s[v][j] == s[i][u]) {
          if (ans[i][j] == 0x3f3f3f3f) {
            ans[i][j] = ans[u][v] + 2;
            q[++tl][0] = i;
            q[tl][1] = j;
          }
        }
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (ans[i][j] == 0x3f3f3f3f) {
        printf("-1 ");
      } else {
        printf("%d ", ans[i][j]);
      }
    }
    puts("");
  }
  return 0;
}